#include "msg_q.hpp"
#include <cstdlib>
#include <cstring>
#include <string>
#include <unistd.h>

using std::cin;

int main()
{
    Client client;

    pid_t pid = fork();
    if (pid == 0)
    {
        // 子进程负责收消息
        while (1)
        {
            string message;
            // 服务端负责收消息
            message = client.Recv(2);
            if (message.size() > 0)
                cout << "Server send  a message: " << message << endl;
            if (message == "quit")
                break;
        }
        exit(0);
    }

    // 客户端负责发消息
    while (1)
    {
        string message;
        getline(cin, message);
        client.Send(message, 1);
        if (message == "quit")
            break;
    }
    return 0;
}